﻿using IdentityServer4;
using IdentityServer4.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace IDS4API
{
    public static class Config
    {
        public static IEnumerable<IdentityResource> IdentityResources =>
            new IdentityResource[]
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),
            };

        public static IEnumerable<ApiResource> ApiResources =>
        new ApiResource[]
        {
            new ApiResource("cpuApi","cpu服务")
            {
                ApiSecrets ={ new Secret("cpuApi secret".Sha256()) },
                Scopes = { "cpuApiScope" }
            },
            new ApiResource("batteryApi","battery服务")
            {
                ApiSecrets ={ new Secret("batteryApi secret".Sha256()) },
                Scopes = { "batteryApiScope" }
            },
            new ApiResource("shellApi","shell服务")
            {
                ApiSecrets ={ new Secret("shellApi secret".Sha256()) },
                Scopes = { "shellApiScope" }
            },
            new ApiResource("packageApi","package服务")
            {
                ApiSecrets ={ new Secret("packageApi secret".Sha256()) },
                Scopes = { "packageApiScope" }
            }
        };

        public static IEnumerable<ApiScope> ApiScopes =>
        new ApiScope[]
        {
            new ApiScope("cpuApiScope"),
            new ApiScope("batteryApiScope"),
            new ApiScope("shellApiScope"),
            new ApiScope("packageApiScope")
        };

        public static IEnumerable<Client> Clients =>
            new Client[]
            {                
                new Client
                {
                    ClientId = "testclient",
                    ClientName = "Client Credentials Client",

                    // 设置 Token 过期时间 3600S 默认3600秒
                    AccessTokenLifetime = 7200,

                    //postman请求
                    //授权码模式（authorization_code）
                    //简化模式（implicit）
                    //密码模式（password）
                    //客户端模式（client_credentials）
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
                    ClientSecrets = { new Secret("testsecret".Sha256()) },

                    AllowedScopes = { "cpuApiScope", "batteryApiScope", "shellApiScope", "packageApiScope" }
                }
            };
    }
}
